package com.lmiot.floatviewsdklibrary.View;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RadialGradient;
import android.graphics.Shader;

public abstract class Ball {
    private static final int mInnerColor = 16777215;
    private static final int mOutterColor = -1426063361;
    protected int[] colors = {16777215, mOutterColor};
    protected float mAngle = 0.0f;
    protected Point mCenter;
    protected int mLeftRadius = 100;
    protected Point mOriginCenter;
    protected int mOriginRadius;
    protected Paint mPaint;
    protected Point mParentCenter;
    protected int mParentRadius;
    protected int mRadius = 100;
    protected int mRightRadius = 100;
    protected float mSizeRate;
    private RadialGradient radialGradient;
    protected float[] stops = {0.5f, 1.0f};

    /* access modifiers changed from: protected */
    public abstract void calculateCenter(float f);

    /* access modifiers changed from: protected */
    public abstract void calculateLeftRadius(float f);

    /* access modifiers changed from: protected */
    public abstract void calculateRadius(float f);

    /* access modifiers changed from: protected */
    public abstract void calculateRightRadius(float f);

    public Ball(int i, int i2, int i3, float f) {
        this.mParentCenter = new Point(i, i2);
        this.mParentRadius = i3;
        this.mSizeRate = f;
        init();
    }

    private void init() {
        this.mCenter = new Point(this.mParentCenter.x, this.mParentCenter.y);
        this.mOriginCenter = new Point(this.mCenter.x, this.mCenter.y);
        int i = (int) (((float) this.mParentRadius) * this.mSizeRate);
        this.mRadius = i;
        this.mOriginRadius = i;
        this.mLeftRadius = i;
        this.mRightRadius = i;
        this.mAngle = 0.0f;
        this.radialGradient = new RadialGradient(0.0f, 0.0f, (float) this.mRadius, this.colors, this.stops, Shader.TileMode.CLAMP);
        Paint paint = new Paint(1);
        this.mPaint = paint;
        paint.setStyle(Paint.Style.FILL);
        this.mPaint.setShader(this.radialGradient);
    }

    public void draw(Canvas canvas) {
        try {
            int i = this.mCenter.x - this.mParentCenter.x;
            int i2 = this.mCenter.y - this.mParentCenter.y;
            canvas.save();
            canvas.translate((float) this.mParentCenter.x, (float) this.mParentCenter.y);
            canvas.rotate(this.mAngle);
            canvas.translate((float) i, (float) i2);
            canvas.save();
            canvas.scale((((float) this.mLeftRadius) * 1.0f) / ((float) this.mOriginRadius), 1.0f);
            int i3 = this.mLeftRadius;
            int i4 = this.mRadius;
            canvas.drawArc((float) (-i3), (float) (-i4), (float) i3, (float) i4, 90.0f, 180.0f, false, this.mPaint);
            canvas.restore();
            canvas.save();
            canvas.scale((((float) this.mRightRadius) * 1.0f) / ((float) this.mOriginRadius), 1.0f);
            int i5 = this.mRightRadius;
            int i6 = this.mRadius;
            canvas.drawArc((float) (-i5), (float) (-i6), (float) i5, (float) i6, -90.0f, 180.0f, false, this.mPaint);
            canvas.restore();
            canvas.restore();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setAngle(float f) {
        this.mAngle = f;
    }

    public void setColorsAndPosition(int[] iArr, float[] fArr) {
        this.colors = iArr;
        this.stops = fArr;
        RadialGradient radialGradient2 = new RadialGradient(0.0f, 0.0f, (float) this.mRadius, iArr, fArr, Shader.TileMode.CLAMP);
        this.radialGradient = radialGradient2;
        this.mPaint.setShader(radialGradient2);
    }

    public void setOffset(int i) {
        float min = Math.min((((float) i) * 1.0f) / ((float) this.mParentRadius), 1.0f);
        calculateRadius(min);
        calculateLeftRadius(min);
        calculateRightRadius(min);
        calculateCenter(min);
    }

    public void setAllRadius(int i) {
        this.mRadius = i;
        this.mOriginRadius = i;
        this.mLeftRadius = i;
        this.mRightRadius = i;
    }
}
